﻿using Abp.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NavGuide.Guide
{
    public class Navigation : Entity<string>
    {
        public Navigation()
        {
            Id = Guid.NewGuid().ToString("N");
            Order = DateTime.Now.DateTimeToInt();
            CreateTime = DateTime.Now;
            IsLeaf = true;
            Items = new List<Navigation>();
        }

        public string ParentId { get; set; }

      //  public virtual Navigation Parent { get; set; }

        public string Name { get; set; }

        public string DisplayName { get; set; }

        public string Icon { get; set; }

        public string Url { get; set; }

        public int Order { get; set; }

        public bool IsLeaf { get; set; }

        public string Account { get; set; }

        public string Key { get; set; }

        public DateTime CreateTime { get; set; }

        public virtual List<Navigation> Items { get; set; }

        public Navigation AddItem(Navigation menuItem)
        {
            Items.Add(menuItem); 
            return this;
        }
    }

    public static class DateTimeExtensions
    {
        /// <summary>
        /// 扩展时间接口，可以返回整形数值
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static int DateTimeToInt(this DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            return (int)(time - startTime).TotalSeconds;
        }
    }

}
